<template>
  <Layout class="p-5 bg-white">
    <Form :label-width="150">
		<Row>
			<Col span="8" push="6">
				<FormItem class="w-50" label="推进人">
					<label>{{ reservationInterview.autorNickName }}</label>
				  </FormItem>
				  <FormItem class="w-50" label="学生姓名">
					<label>{{ reservationInterview.studentName }}</label>
				  </FormItem>
				  <FormItem class="w-75" label="新增预约回访日期">
					  <Date-picker
					    :value="this.formatDate(new Date())+' 00:00:00'"
						type="datetime"
						placeholder="预约到访开始时间"
						@on-change="dateChange"
					  ></Date-picker>
				  </FormItem>
				</FormItem>
			</Col>
		</Row>
		<Row>
			<Col span="8" push="4">
				<FormItem class="text-right">
				  <Button @click="submit" type="primary">提交</Button>
				  <Button @click="cancel" class="ml-2">取消</Button>
				</FormItem>
			</Col>
		</Row>
    </Form>
  </Layout>
</template>

<script>
	export default {
		data() {
			return {
				reservationInterview: {
					autorNickName: '',
					studentName: '',
					autor: null,
					addReservationInterviewTime: this.formatDate(new Date()) + ' 00:00:00',
					dateTime: '',
					cu: null,
					ct: '',
					uu: null,
					ut: '',
				},
				allStages: [], //XX
			}
		},
		methods: {
			formatDate: function(date) {
				//格式化日期方法! ----> yyyy-MM-dd
				var d = new Date(date),
					month = '' + (d.getMonth() + 1),
					day = '' + d.getDate(),
					year = d.getFullYear()

				if (month.length < 2) month = '0' + month
				if (day.length < 2) day = '0' + day
				return [year, month, day].join('-')
			},
			dateChange: function(datetime) {
				this.reservationInterview.addReservationInterviewTime = datetime
			},
			changeP: function(selectedPermissionId) {
				if (selectedPermissionId === 0) {
					this.$data.permission.path = ''
				}
			},
			submit: function() {
				//submit----
				let self = this

				// if (this.$data.reservationInterview.addReservationInterviewTime === '') {
				//   this.message.error('请输入预约接待时刻')
				//   return
				// }

				var reservationInterview = {
					studentId: this.$route.params.row.studentId,
					datetime: this.reservationInterview.addReservationInterviewTime,
					uu: this.reservationInterview.uu,
					id: this.$route.params.row.reservationInterviewId,
					autor: this.$route.params.row.autorId
				}

				this.http
					.put({
						url: '/common/interview',
						param: reservationInterview,
					})
					.then((data) => {

						if (this.$route.params.stageId === 1) {

											this.$tabs.close({to :'/resource'})
									}

									if (this.$route.params.stageId === 2) {

											this.$tabs.close({to :'/interview'})
									}

									if (this.$route.params.stageId === 3) {

											this.$tabs.close({to :'/try'})
									}

					})
			}, //submit----
			cancel: function() {
				if (this.$route.params.stageId === 1) {

									this.$tabs.close({to :'/resource'})
							}

							if (this.$route.params.stageId === 2) {

									this.$tabs.close({to :'/interview'})
							}

							if (this.$route.params.stageId === 3) {

									this.$tabs.close({to :'/try'})
							}
			},
			init: function() {},
		},
		destroyed: function() {
			//跳转页面!
			if (this.$route.params.stageId === 1) {
				this.$router.push({
					name: 'resource',
				})
			}

			if (this.$route.params.stageId === 2) {
				this.$router.push({
					name: 'interview',
				})
			}

			if (this.$route.params.stageId === 3) {
				this.$router.push({
					name: 'try',
				})
			}
		},
		created: function() {
			this.init()
			this.reservationInterview.autorNickName = this.$route.params.row.autor
			this.reservationInterview.studentName = this.$route.params.row.name
			let currentUser = JSON.parse(sessionStorage.getItem('CURRENT_USER'));
			this.reservationInterview.uu = currentUser.user.userId;

		},
	}
</script>

<style></style>
